home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / handlers / example4.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  4KB  |  126 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Handlers                    Tulevagen 22       */
  8. /* File:    Example4.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-16                                       */
  11. /* Version: 1.1                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to use the Speaker ("SPEAK:") */
  21. /* handler. We will simply open the Speaker handler and set    */
  22. /* the speed to be very slow. Then we send some text to the    */
  23. /* handler and it will automatically be translated and read    */
  24. /* out loud for us.                                            */
  25. /*                                                             */
  26. /* Yes, it was very late when I wrote this example...          */
  27.  
  28.  
  29.  
  30. /* Include the dos library definitions: */
  31. #include <dos/dos.h>
  32.  
  33. /* Now we include the necessary function prototype files:         */
  34. #include <clib/dos_protos.h>       /* General dos functions...    */
  35. #include <clib/exec_protos.h>      /* System functions...         */
  36. #include <stdio.h>                 /* Std functions [printf()...] */
  37. #include <stdlib.h>                /* Std functions [exit()...]   */
  38. #include <string.h>                /* Std functions [strlen()...] */
  39.  
  40.  
  41.  
  42. /* Set name and version number: */
  43. UBYTE *version = "$VER: AmigaDOS/Handlers/Example4 1.1";
  44.  
  45.  
  46.  
  47. /* Declared our own function(s): */
  48.  
  49. /* Our main function: */
  50. int main( int argc, char *argv[] );
  51.  
  52.  
  53.  
  54. /* Main function: */
  55.  
  56. int main( int argc, char *argv[] )
  57. {
  58.   /* Here is the text we want the Amiga to read: */
  59.   UBYTE *my_text = "I am very tired.";
  60.  
  61.   /* A "BCPL" pointer to our Speaker handler: */
  62.   BPTR my_translator;
  63.   
  64.   /* Store here the number of characters actually spoken: */
  65.   long characters_spoken;
  66.  
  67.  
  68.  
  69.   /* We will now open the Speaker handler ("SPEAK:"). Any data */
  70.   /* which is send to this handler will be translated and then */
  71.   /* read out loud. Please note that you can of course only    */
  72.   /* send data to the Speaker handler, not read.               */
  73.   /*                                                           */
  74.   /* The Speaker handler accepts some useful options:          */ 
  75.   /*   /n    Speak with a natural voice                        */
  76.   /*   /m    Speak with a man voice                            */
  77.   /*   /f    Speak with a "female" voice                       */
  78.   /*   /r    Speak like a robot with a monototonous voice      */
  79.   /*   /sXXX Speed, 40 - 400                                   */
  80.   /*   /pXXX Pitch, 65 - 320                                   */
  81.   /*                                                           */
  82.   /* Open the Speaker handler, use natural voice with very     */
  83.   /* slow speed:                                               */
  84.   my_translator = 
  85.    Open( "SPEAK:OPT/n/s40", MODE_NEWFILE );
  86.   
  87.   /* Have we opened the Speaker handler successfully? */
  88.   if( my_translator == NULL )
  89.   {
  90.     /* Problems, inform the user: */
  91.     printf( "Error! Could not open the Speaker handler!\n" );
  92.  
  93.     /* Exit with an error code: */
  94.     exit( 20 );
  95.   }
  96.  
  97.  
  98.  
  99.   /* "Read" one line: (Note that with "read" I mean read */
  100.   /* like "speaking", and not like collecting data.)     */
  101.   characters_spoken =
  102.     Write( my_translator, my_text, strlen( my_text ) );
  103.  
  104.   /* Was the whole line "read": */
  105.   if( characters_spoken != strlen( my_text ) )
  106.   {
  107.     /* No! We could not "read" the whole line! */
  108.     printf( "Error! Could not \"read\" all text!\n" );
  109.  
  110.     /* Close the Speaker handler: */
  111.     Close( my_translator );
  112.  
  113.     /* Exit with an error code: */
  114.     exit( 21 );
  115.   }
  116.  
  117.  
  118.  
  119.   /* Close the Speaker handler: */
  120.   Close( my_translator );
  121.  
  122.   /* The End! */
  123.   exit( 0 );
  124. }
  125.  
  126.